//package com.app.service.authority;
//
//import java.util.List;
//
//import com.app.entity.authority.SecurityUser;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.security.core.userdetails.UsernameNotFoundException;
//import org.springframework.stereotype.Service;
//
//import com.app.entity.authority.User;
//import com.app.mapper.authority.UserMapper;
//
//@Service
//public class UserService {
//
//
//	@Autowired
//	UserMapper userMapper;
//
//
//
//	public SecurityUser loadUserByUsername(String loginName)    {
//		//SysUser对应数据库中的用户表，是最终存储用户和密码的表，可自定义
//		//本例使用SysUser中的name作为用户名:
//		User user = userMapper.loadUser(loginName);
//		if (user == null) {
//			throw new UsernameNotFoundException("UserName " + user.getName() + " not found");
//		}
//		// SecurityUser实现UserDetails并将SysUser的name映射为username
//		SecurityUser seu = new SecurityUser(user);
//		return  seu;
//	}
//
//	public User login(String loginname, String password) {
//		return userMapper.selectUser(loginname,password);
//
//	}
//	/**
//	 * �û��б�
//	 * @return
//	 */
//	public List<User> queryUser(){
//		return userMapper.query();
//	}
//
//	/**
//	 * ɾ���û�
//	 * @param id
//	 * @return
//	 */
//	public User deleteUser(String id){
//		return userMapper.deleteUser(id);
//	}
//	/**
//	 * �����û�
//	 * @param user
//	 * @return
//	 */
//	public User insertUser(User user){
//		return userMapper.insertUser(user);
//	}
//	public User updateUser(User user){
//		return userMapper.updateUser(user);
//	}
//}
package com.app.service.authority;

import java.util.List;

import com.app.entity.authority.SecurityUser;

import com.app.entity.authority.User;
import org.springframework.beans.factory.annotation.Autowired;

import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.stereotype.Service;

import com.app.mapper.authority.UserMapper;

@Service
public class UserService  implements UserDetailsService{


	@Autowired
	UserMapper userMapper;



	public SecurityUser loadUserByUsername(String loginName)    {
		//SysUser对应数据库中的用户表，是最终存储用户和密码的表，可自定义
		//本例使用SysUser中的name作为用户名:
		User user = userMapper.loadUser(loginName);
		if (user == null) {
			throw new UsernameNotFoundException("UserName " + user.getName() + " not found");
		}
		// SecurityUser实现UserDetails并将SysUser的name映射为username
		SecurityUser seu = new SecurityUser(user);
		return  seu;
	}

	public User login(String id) {
		return userMapper.selectUser(id);

	}
	/**
	 * �û��б�
	 * @return
	 */
	public List<User> queryUser(){
		return userMapper.query();
	}

	/**
	 * ɾ���û�
	 * @param id
	 * @return
	 */
	public User deleteUser(String id){
		return userMapper.deleteUser(id);
	}
	/**
	 * �����û�
	 * @param user
	 * @return
	 */
	public User insertUser(User user){
		return userMapper.insertUser(user);
	}
	public User updateUser(User user){
		return userMapper.updateUser(user);
	}
}
